// AOWatchdogClient.cpp : main project file.
//  AmbientOrbSerialLib.dll is registered via RegAsm.exe ManagedDLL.dll /tlb:ManagedDLL.tlb /codebase


#include "stdafx.h"
#include "Form1.h"

using namespace com::n3te::AmbientOrbSerialLib;
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;


public ref class Form1: public System::Windows::Forms::Form
{
private:
   System::Windows::Forms::NotifyIcon^ notifyIcon1;
   System::Windows::Forms::ContextMenu^ contextMenu1;
   System::Windows::Forms::MenuItem^ menuItem1;
   System::ComponentModel::IContainer^ components;
   AmbientOrbSerialLib^ aoSerialLib;

public:
   Form1()
   {
      components = gcnew System::ComponentModel::Container;
      contextMenu1 = gcnew System::Windows::Forms::ContextMenu;
      menuItem1 = gcnew System::Windows::Forms::MenuItem;

      // Initialize contextMenu1
      array<System::Windows::Forms::MenuItem^>^temp0 = {menuItem1};
      contextMenu1->MenuItems->AddRange( temp0 );

      // Initialize menuItem1
      menuItem1->Index = 0;
      menuItem1->Text = "E&xit";
      menuItem1->Click += gcnew System::EventHandler( this, &Form1::menuItem1_Click );

      // Set up how the form should be displayed.
      ClientSize = System::Drawing::Size( 292, 266 );
      Text = "Notify Icon Example";

      // Create the NotifyIcon.
      notifyIcon1 = gcnew System::Windows::Forms::NotifyIcon( components );

      // The Icon property sets the icon that will appear
      // in the systray for this application.
      notifyIcon1->Icon = gcnew System::Drawing::Icon( "app.ico" );

      // The ContextMenu property sets the menu that will
      // appear when the systray icon is right clicked.
      notifyIcon1->ContextMenu = contextMenu1;

      // The Text property sets the text that will be displayed,
      // in a tooltip, when the mouse hovers over the systray icon.
      notifyIcon1->Text = "AO Watchdog";
      notifyIcon1->Visible = true;

      // Handle the DoubleClick event to activate the form.
      notifyIcon1->DoubleClick += gcnew System::EventHandler( this, &Form1::notifyIcon1_DoubleClick );
   }

protected:
   ~Form1()
   {
      if ( components != nullptr )
      {
         delete components;
      }
   }

private:
   void notifyIcon1_DoubleClick( Object^ /*Sender*/, EventArgs^ /*e*/ )
   {

      // Show the form when the user double clicks on the notify icon.
      // Set the WindowState to normal if the form is minimized.
      if ( WindowState == FormWindowState::Minimized )
            WindowState = FormWindowState::Normal;

      // Activate the form.
      Activate();
   }

   void menuItem1_Click( Object^ /*Sender*/, EventArgs^ /*e*/ )
   {

      // Close the form, which closes the application.
      Close();
   }

};



[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 
	

	// Create the main window and run it
	Application::Run(gcnew Form1());

	String^ sComName = "Com3";	
	try {
		aoSerialLib = gcnew AmbientOrbSerialLib(sComName);
	}
	catch (Exception *e) {
		
	}

	return 0;
}
